package interview;

public class interview_04_04 {
    public boolean isBalanced(TreeNode root) {
        boolean[] flag=new boolean[1];
        flag[0]=true;
        depth(root,flag);
        return flag[0];
    }
    public int depth(TreeNode node,boolean[] flag){
        if(node==null) return 0;
        int left=depth(node.left,flag);
        int right=depth(node.right,flag);
        if(Math.abs(left-right)>1) flag[0]=false;
        return Math.max(left,right)+1;
    }
}
